﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sakura.Games.StgFramework.Builder.Design
{
	/// <summary>
	/// 为所有使用资源字典加载设计值的自定义属性提供基础类型。
	/// </summary>
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
	public abstract class SRAttribute : Attribute
	{
		/// <summary>
		/// 获取资源的名称。
		/// </summary>
		public string ResourceName
		{
			get;
			private set;
		}

		/// <summary>
		/// 用指定的资源名称初始化一个新的属性。
		/// </summary>
		/// <param name="resourceName">属性对应的资源名称。</param>
		protected SRAttribute(string resourceName)
		{
			if (resourceName == null)
			{
				throw new ArgumentNullException("resourceName");
			}

			this.ResourceName = resourceName;
		}

		/// <summary>
		/// 获得该对象对应的资源。
		/// </summary>
		/// <returns>该对象对应的资源。</returns>
		public object GetResource()
		{
			var manager = new System.Resources.ResourceManager(this.GetType());
			return manager.GetObject(this.ResourceName);
		}
	}
}
